<?php
namespace app\api\controller;
use app\admin\model\service\Agent;
use app\admin\model\service\AgentUser;
use app\common\controller\Api;
class ServiceAgent extends Api
{
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }
    //服务站列表
    public function siteList(){
        $agentModel = new Agent();
        $serviceAgent = $agentModel->get(["user_id"=>$this->auth->getUser()->id]);
        if($serviceAgent && $serviceAgent->type == 2){
            $list = $agentModel->where(["pid"=>$serviceAgent->id,"type"=>3])->order("id", "desc")->paginate();
            $this->success("success", $list);
        }
        $this->error("身份不是服务中心");
    }
    //服务站详情
    public function site(){
        $id = $this->request->get("id");
        if($id){
            $site = (new Agent())->where("id", $id)->with(['area','product_category','env_category','service_agent_details'])->find();
            $this->success("success", $site);
        }
        $this->error("id不存在");
    }
    //员工列表
    public function employeeList(){
        $agentModel = new Agent();
        $serviceAgent = $agentModel->get(["user_id"=>$this->auth->getUser()->id]);
        $list = (new AgentUser())->where("service_agent_id", $serviceAgent->id)->order("id", "desc")->paginate();
        $this->success("success", $list);
    }
}
